﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using LuWeibo.ViewModels;
using LuWeibo.Models;

namespace LuWeibo.Views
{
    //指定某个用户的微博以及用户信息页面
    public partial class UsersStatusPage : PhoneApplicationPage
    {
        private UserInfoViewModel userInfoViewModel;

        public UsersStatusPage()
        {
            InitializeComponent();

            userInfoViewModel = (UserInfoViewModel)this.DataContext;
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (this.NavigationContext.QueryString.ContainsKey("uid"))
            {
                Int64 uid = Convert.ToInt64(this.NavigationContext.QueryString["uid"]);
                userInfoViewModel.UID = uid;
                userInfoViewModel.SearchUserExecute();
                userInfoViewModel.GetTrendsList();
            }
            else
            {
                MessageBox.Show("没有用户信息传递过来!");
            }
            base.OnNavigatedTo(e);
        }

        private void UserInfoPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (UserInfoPivot.SelectedIndex == 0) //个人资料
            {
                this.userInfoViewModel.SearchUserExecute();
                this.userInfoViewModel.GetTrendsList();
            }
            else if (UserInfoPivot.SelectedIndex == 1) //微博
            {
                this.userInfoViewModel.GetCurrentUserStatus();
            }
            else if (UserInfoPivot.SelectedIndex == 2)//关注
            {
                this.userInfoViewModel.GetFriendShip();
            }
            else if (UserInfoPivot.SelectedIndex == 3)//粉丝
            {
                this.userInfoViewModel.GetFans();
            }
        }

        private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Border selectedBorder = (Border)sender;
            if ("关注".Equals(selectedBorder.Tag))
            {
                userInfoViewModel.GetFriendShip();
                this.UserInfoPivot.SelectedIndex = 2;
            }
            else if ("微博".Equals(selectedBorder.Tag))
            {
                userInfoViewModel.GetCurrentUserStatus();
                this.UserInfoPivot.SelectedIndex = 1;
            }
            else if ("粉丝".Equals(selectedBorder.Tag))
            {
                userInfoViewModel.GetFans();
                this.UserInfoPivot.SelectedIndex = 3;
            }
            else if ("话题".Equals(selectedBorder.Tag))
            {
                userInfoViewModel.GetTrendsList();
                this.UserInfoPivot.SelectedIndex = 4;
            }
        }

        private void FriendShipList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox listbox = (ListBox)sender;
            User selectedUser = listbox.SelectedItem as User;
            if (selectedUser != null)
            {
                //userInfoViewModel.CurrentUser = selectedUser;
                userInfoViewModel.UID = Convert.ToInt64(selectedUser.id);
                UserInfoPivot.SelectedIndex = 0;
            }
        }
    }
}